package com.qf;

import com.qf.model.Device;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class test5 {

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void demo01(){

        long start = System.currentTimeMillis();

        redisTemplate.executePipelined(new SessionCallback<String>() {
            @Override
            public <K, V> String execute(RedisOperations<K, V> operations) throws DataAccessException {
                for (int i = 0; i < 10000; i++) {
                    redisTemplate.opsForValue().set("key"+i,"value"+i);
                }
                return null;
            }
        });
        long end = System.currentTimeMillis();

        System.out.println("--->" + (end - start));

    }



    @Test
    public void demo02(){

        long start = System.currentTimeMillis();


                for (int i = 20000; i < 30000; i++) {
                    redisTemplate.opsForValue().set("key"+i,"value"+i);
                }

        long end = System.currentTimeMillis();

        System.out.println("--->" + (end - start));

    }
}
